package com.swust.excel.read.onesheet;

import com.alibaba.excel.EasyExcel;

public class ReadOneMain {

    public static void main(String[] args) {
        /*
        * 如果是网页接口，读取模板得换一种形式，如下所示
                RiverAffairsOrder dto = riverAffairsOrders.get(0);
                //返回体设置
                response.setContentType("application/vnd.ms-excel");
                response.setCharacterEncoding("utf-8");
                String excelName = dto.getCreateTimeYm() + "_" + dto.getUnitName() + ".xlsx";
                excelName = URLEncoder.encode(excelName, "UTF-8");
                response.setHeader("Content-disposition", "attachment;filename=" + excelName);
                //
                ClassPathResource classPathResource = new ClassPathResource(File.separator + "templates" + File.separator + "river_affairs.xlsx");
                EasyExcel.write(response.getOutputStream(), RiverAffairsOrder.class)
                        .withTemplate(classPathResource.getInputStream())
                        .autoCloseStream(Boolean.FALSE)
                        .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
                        .sheet()
                        .doFill(dto);
        * */
        String fileName = ReadOneMain.class.getResource("/").getPath() + "read/onesheet.xlsx";
        // 这里 需要指定读用哪个class去读，然后读取第一个sheet 文件流会自动关闭
        EasyExcel.read(fileName, ReadOneBean.class, new ReadOneListener()).sheet().doRead();
    }
}
